(function($){

	function bindClick(){

	}

	function initHeight(){
		var headerHeight = $('.ag-search')[0].offsetHeight;
		var footerHeight = $('.ag-bar').height();
		var screenHeight = window.screen.height * getDPR();
		var bodyHeight = screenHeight - footerHeight - headerHeight;
		$('.ag-nav > ul ,.ag-nav .ag-content').css('height',
					(bodyHeight)+'px');
	}

	initHeight();


	function getDPR(){
		var win = window;
		var doc = win.document;
	    var docEl = doc.documentElement;
	    var metaEl = doc.querySelector('meta[name="viewport"]');
	    var flexibleEl = doc.querySelector('meta[name="flexible"]');
	    var dpr = 0;//设备像素比率（Device Pixel Ratio，DPR）：物理像素与逻辑像素（px）的对应关系
	    var scale = 0;//缩放比例
	    var tid;
	    var flexible = lib.flexible || (lib.flexible = {});

	    if (metaEl) {//判断是否设置viewport
	        console.warn('将根据已有的meta标签来设置缩放比例');
	        var match = metaEl.getAttribute('content').match(/initial\-scale=([\d\.]+)/);
	        if (match) {
	            scale = parseFloat(match[1]);
	            dpr = parseInt(1 / scale);
	        }
	    } else if (flexibleEl) { //手动配置dpr
	        var content = flexibleEl.getAttribute('content');
	        if (content) {
	            var initialDpr = content.match(/initial\-dpr=([\d\.]+)/);
	            var maximumDpr = content.match(/maximum\-dpr=([\d\.]+)/);
	            if (initialDpr) {
	                dpr = parseFloat(initialDpr[1]);
	                scale = parseFloat((1 / dpr).toFixed(2));
	            }
	            if (maximumDpr) {
	                dpr = parseFloat(maximumDpr[1]);
	                scale = parseFloat((1 / dpr).toFixed(2));
	            }
	        }
	    }

	    if (!dpr && !scale) {//dpr设置
	        var isAndroid = win.navigator.appVersion.match(/android/gi);
	        var isIPhone = win.navigator.appVersion.match(/iphone/gi);
	        var devicePixelRatio = win.devicePixelRatio;
	        if (isIPhone) {
	            // iOS下，对于2和3的屏，用2倍的方案，其余的用1倍方案
	            if (devicePixelRatio >= 3 && (!dpr || dpr >= 3)) {
	                dpr = 3;
	            } else if (devicePixelRatio >= 2 && (!dpr || dpr >= 2)){
	                dpr = 2;
	            } else {
	                dpr = 1;
	            }
	        } else {
	            // 其他设备下，仍旧使用1倍的方案
	            dpr = 1;
	        }
	        scale = 1 / dpr;
	    }

	    return dpr;
	}

})(jQuery);

